<template>
  <el-dialog
      title="新建组织"
      :visible.sync="open"
      width="700px"
      append-to-body
      @close="resetForm"
  >
    <span style='font-size: 17px;'>基本信息</span>
    <br>
<!--    {{JSON.stringify(form,null,4)}}-->
    <el-form ref="form" :rules="rules" :model="form" label-width="120px"  style='margin-top: 20px;'>
      <el-row>
        <el-col :span="12">
          <el-form-item label="组织名称" prop="name" >
            <el-input
                v-model="form.name"
                placeholder="组织名称"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="分类" prop="category" >
            <el-select v-model="form.category" disabled  placeholder="请选择" style="width:100%">
              <el-option label="企业" :value="1" />
<!--              <el-option label="部门" :value="2" />-->
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
<!--          <el-form-item label="经营状态" prop="status">-->
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" disabled placeholder="请选择" style="width:100%">
              <el-option label="存续" value="1"/>
              <el-option label="注销" value="2"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="组织类型"  prop="type">
            <el-select v-model="form.type" disabled placeholder="请选择" style="width:100%">
              <el-option label="外部" :value="0"/>
<!--              <el-option label="内部" :value="1"/>-->
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="证件类型" prop="idType" >
            <el-select v-model="form.idType" disabled placeholder="请选择" style="width:100%">
              <el-option label="统一社会信用代码" :value="1" />
              <el-option label="身份证" :value="2" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="证件号码" prop="idNo"  >
            <el-input v-model="form.idNo" placeholder="请输入"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="联系地址" prop="contractAddress"  >
            <el-input type="textarea" :row="2" v-model="form.contractAddress" placeholder="请输入" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {addRelativeEnterprise,} from '@/api/organizationOuter/etpApi'
import {idChange} from '@/utils/fengwenxin_utils'
let defaultForm = {
  name:'',
  category:1,
  status: "1",
  type:0,
  idType:1,
  idNo:"",
  contractAddress:"",
}
export default {
  data() {
    return {
      form: JSON.parse(JSON.stringify(defaultForm)),
      open: false,
      rules:{
        name: [
          { required: true, message: '请输入企业名称', trigger: 'change' },
          { min: 2, max: 50, message: '组织名称请输入2-25个字',  trigger: 'change' }
        ],
        category: [
          { required: true, message: '请选择分类', trigger: 'change' },
        ],
        account: [
          { required: true, message: '还没有生成组织编码', trigger: 'change' },
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'change' },
        ],
        idNo: [
          {  validator:idChange, trigger: 'change' }
        ],
      }
    };
  },
  methods: {
    handleadd() {
      this.open = true;
    },
    submitForm() {
      // console.log('jiek', this.form)
      this.$refs['form'].validate(valid=>{
        if(!valid) return;
        const post_data  = Object.assign({},this.form)
        delete post_data.category; // 不用传
        delete post_data.type; // 不用传
        addRelativeEnterprise(this.form).then((response) => {
          this.$message({
            message: '提交成功',
            type: 'success'
          });
          this.open = false;
          this.$emit("getList");
        }).catch(err=>{
          console.error('err',err)
        });
      })

    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 重置按钮操作 */
    resetForm() {
      this.form = JSON.parse(JSON.stringify(defaultForm))
    },
  },
};
</script>
<style scoped>
</style>
